package cn.zcy.controller.i18n;

import cn.zcy.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

@Controller
public class I18NController {

    @RequestMapping("/i18n")
    public String i18(User user){
        System.out.println("国际化");
        return "i18n";
    }
@RequestMapping("/i18n/{language}_{country}")
    public String changeLocale(@PathVariable(value = "language") String language,
                               @PathVariable(value = "country") String country,
                               @Autowired SessionLocaleResolver localeResolver,
                               HttpServletRequest request ,
                               HttpServletResponse response){
    Locale locale1=new Locale(language,country);
    localeResolver.setLocale(request,response,locale1);
    return "i18n";
}
}
